<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @toExport="toExport"
      :isHaveAdd="false"
      exportUrl="/api/admin/export/money"
    >
      <template v-slot:search>
        <moneySearch
          @sendSearch="getSearch"
          @sendMoney="getMoney"
        ></moneySearch>
      </template>
      <template v-slot:table>
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="list.data"
          stripe
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.nickname || "----" }}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span @click="func_1(scope.row.uid)" style="cursor:pointer">{{
                    scope.row.username
                  }}</span>
                </div>
                <div>
                  <span>会员备注：</span>
                  <span>{{ scope.row.admin_remark }}</span>
                </div>
                <div>
                  <span>用户等级：</span>
                  <span class="rat" v-show="scope.row.rating_cn">{{
                    scope.row.rating_cn
                  }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单" min-width="250">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>订单号：</span>
                  <span @click="func_2(scope.row.oid)">{{
                    scope.row.oid
                  }}</span>
                </div>
                <div>
                  <span>时间：</span>
                  <span>{{ scope.row.created_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>备注：</span>
                  <span>{{ scope.row.remark }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="资金" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>资金增减：</span>
                  <span>
                    {{ scope.row.money }}
                    {{ scope.row.style_cn }}
                  </span>
                </div>
                <div>
                  <span>剩余资金：</span>
                  <span>
                    {{ scope.row.balance }}
                    {{ scope.row.style_cn }}
                  </span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="来源" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>来源昵称：</span>
                  <span>{{ scope.row.ly_nickname || "----" }}</span>
                </div>
                <div>
                  <span>来源账号：</span>
                  <span
                    @click="func_1(scope.row.ly_id)"
                    style="cursor:pointer"
                    >{{ scope.row.ly_name }}</span
                  >
                </div>
                <div>
                  <span>来源备注：</span>
                  <span>{{ scope.row.ly_admin_remark }}</span>
                </div>
                <div>
                  <span>来源等级：</span>
                  <span class="rat" v-show="scope.row.ly_rating_cn">{{
                    scope.row.ly_rating_cn
                  }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="资金类型" align="center" min-width="100">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>{{ scope.row.cate_cn }}</span>
                  <span></span>
                </div>
                <div>
                  <span></span>
                  <span
                    class="rat"
                    :class="[
                      scope.row.style == '积分抵用'
                        ? 'lei_red'
                        : scope.row.style == '加佣金'
                        ? 'tx'
                        : 'sh'
                    ]"
                    >{{ scope.row.style }}</span
                  >
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <div class="recharge_sum">
          <p>
            <span>累计搜索加金额：</span>
            {{ $fnc.toFixedZ(count.plus, 3) }}
          </p>
          <p>
            <span>累计搜索减金额：</span>
            {{ $fnc.toFixedZ(count.minus, 3) }}
          </p>
        </div>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import moneySearch from "@/components/currency/moneySearch.vue";
export default {
  components: {
    moneySearch
  },
  props: {
    oid: null
  },
  data() {
    return {
      username: "",
      count: {},
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {
        username: ""
      },
      item: {
        cate: ""
      }
    };
  },

  methods: {
    toExport(str) {
      if (str) {
        var params = JSON.parse(JSON.stringify(this.searchAll));
        this.$fnc.postExcelFile(params, str);
      } else {
        this.$fnc.alertError("请检查地址", str);
      }
    },
    get_count() {
      var params = this.searchAll;
      this.$api.getAdmin.get_money_count(params).then(res => {
        if (res.data.code == 200) {
          this.count = res.data.result;
        }
        this.loading = false;
      });
    },
    getMoney(obj) {
      this.item = obj;
      for (var i in this.item) {
        obj[i] = this.item[i];
      }

      this.searchAll = obj;
      this.$router.push(this.$route.path + "?page=" + 1);
      this.getNewsAll(this.searchAll);
    },
    getSearch(obj) {
      for (var i in this.item) {
        obj[i] = this.item[i];
      }
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      params.oid = this.oid || data.oid || "";

      params.username = params.username || this.username || "";
      this.$api.getUser.getMoneyList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
          this.get_count();
        } else {
          this.$fnc.alertError(res.data.result);
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;

      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      // console.log(`当前页:`+val)
      this.$router.push(this.$route.path + "?page=" + val);
    },

    func_1(val) {
      let routeData = this.$router.resolve({
        path: "/index/user/user_info",
        query: { id: val }
      });
      window.open(routeData.href, "_blank");
    },
    func_2(val) {
      // this.$router.push({path: '/index/order/addorder',query:{ id:val}});
    }
  },
  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);

      this.currentPage = Number(this.$route.query.page) || 1;
    }
  },
  created() {
    if (this.$route.query.username) {
      this.username = this.$route.query.username;
    }
    var params = this.searchAll;
    params.page = this.$route.query.page || 1;
    params.page_size = this.pageSize;
    params.oid = this.oid;
    this.getNewsAll(params);
    this.currentPage = Number(this.$route.query.page) || 1;
  },
  filters: {
    toFixedTwo(val) {
      var num = val.indexOf(".");

      return val.substring(0, num + 4);
    }
  },
  computed: {}
};
</script>

<style scoped>
.recharge_sum {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  padding-left: 10px;
}
.recharge_sum p {
  font-size: 14px;
  line-height: 32px;
  padding-right: 50px;
  text-align: left;
}
.recharge_sum span {
  font-size: 14px;
  font-weight: bold;
}
</style>
